/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isd.inventario.modelo;

import isd.general.modelo.GR_Auditoria;
import isd.general.modelo.GR_Comprobante;
import isd.general.modelo.GR_Formulario;
import isd.general.modelo.GR_Sucursal;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author ctrosch
 */
@Entity
@Table(name = "strmvh")
@IdClass(ST_MovimientoPK.class)
public class ST_Movimiento implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "STRMVH_MODFOR", nullable = false, length = 2)
    private String modfor;

    @Id
    @Column(name = "STRMVH_CODFOR", nullable = false, length = 6)
    private String codfor;

    @Id
    @Column(name = "STRMVH_NROFOR", nullable = false)
    private int nrofor;

    @Id
    @Column(name = "STRMVH_SUCURS", nullable = false, length = 6)
    private String sucurs;

    @JoinColumns({
    @JoinColumn(name = "STRMVH_MODFOR", referencedColumnName = "GRCFOR_MODFOR", nullable = false,insertable=false, updatable=false),
    @JoinColumn(name = "STRMVH_CODFOR", referencedColumnName = "GRCFOR_CODFOR", nullable = false,insertable=false, updatable=false)
    })
    @ManyToOne
    GR_Formulario formulario;
    /**
     * Comprobante de stock
     */
    @JoinColumns({
    @JoinColumn(name = "STRMVH_MODCOM", referencedColumnName = "GRCCBH_MODCOM", nullable = false),
    @JoinColumn(name = "STRMVH_CODCOM", referencedColumnName = "GRCCBH_CODCOM", nullable = false)
    })
    @ManyToOne
    GR_Comprobante comprobante;


    //Sucursal o punto de venta
    @JoinColumn(name = "STRMVH_SUCURS", referencedColumnName = "GRTSUC_SUCURS", nullable = false,insertable=false,updatable=false)
    @ManyToOne
    private GR_Sucursal sucursal;

    /**
     * Fecha movimiento
     */
    @Basic(optional = false)
    @Column(name = "STRMVH_FCHMOV", nullable = false)
    @Temporal(TemporalType.TIMESTAMP)
    private Date fechaMovimiento;

    /**
     * Tipo de movimiento
     * A = Ajuste
     * I = Ingreso
     * E = Egreso
     * T = Transferencia
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "STRMVH_TIPMOV", length = 1)
    private ST_TipoMovimiento tipoMovimiento;
    @Basic(optional = false)

    /**
     * Nro de cuenta cliente
     */
    @Column(name = "STRMVH_NROCVT", length = 13)
    private String nroCuentaVenta;

    /**
     * Nro de cuenta proveedor
     */
    @Column(name = "STRMVH_NROCPV", length = 13)
    private String nroCuentaProveedor;

    /**
     * Deposito egreso
     */
    @JoinColumn(name = "STRMVH_DEPEGR", referencedColumnName = "STTDEH_DEPOSI")
    @ManyToOne(optional=false)
    private ST_Deposito depositoEgreso;

    /**
     * Sector egreso
     */
    @JoinColumns({
        @JoinColumn(name = "STRMVH_DEPEGR", referencedColumnName = "STTDEI_DEPOSI", nullable = false,insertable=false, updatable=false),
        @JoinColumn(name = "STRMVH_SECEGR", referencedColumnName = "STTDEI_SECTOR", nullable = false)
    })
    @ManyToOne
    private ST_Sector sectorEgreso;

        /**
     * Deposito ingreso
     */
    @JoinColumn(name = "STRMVH_DEPING", referencedColumnName = "STTDEH_DEPOSI", insertable=false, updatable=false)
    @ManyToOne(optional=false)
    private ST_Deposito depositoIngreso;

    /**
     * Sector ingreso
     */
    @JoinColumns({
        @JoinColumn(name = "STRMVH_DEPING", referencedColumnName = "STTDEI_DEPOSI", nullable = false),
        @JoinColumn(name = "STRMVH_SECING", referencedColumnName = "STTDEI_SECTOR", nullable = false)
    })
    @ManyToOne
    private ST_Sector sectorIngreso;

    /**
     * Mascara de stock
     */
    @Column(name = "STRMVH_MASCAR", length = 6)
    private String mascara;
    /**
     * Observaciones textos
     */
    @Lob
    @Column(name = "STRMVH_TEXTOS", length = 65535)
    private String textos;

    /**
     *  Control de impresión
     */
    @Column(name = "STRMVH_IMPRES")
    private Short controlDeImpresion;
    /**
     * Dimensión obligatoria
     */
    @Column(name = "STRMVH_DIMOBL", length = 6)
    private String dimobl;
    @Column(name = "STRMVH_SUBCUE", length = 40)
    private String subcue;
    @Column(name = "STRMVH_DIMORI", length = 6)
    private String dimori;
    @Column(name = "STRMVH_SUBORI", length = 40)
    private String subori;
    @Column(name = "STRMVH_HSTFOR")
    private Short hstfor;
    
    @Column(name = "STRMVH_COFLIS", length = 6)
    private String coflis;
    @Column(name = "STRMVH_CAMBIO", precision = 20, scale = 8)
    private BigDecimal cambio;
    @Column(name = "STRMVH_MODASI", length = 2)
    private String modasi;
    @Column(name = "STRMVH_CODASI", length = 6)
    private String codasi;
    @Column(name = "STRMVH_NROASI")
    private Integer nroasi;
    @Column(name = "STRMVH_MODREP", length = 2)
    private String modrep;
    @Column(name = "STRMVH_CODREP", length = 6)
    private String codrep;
    @Column(name = "STRMVH_NROREP")
    private Integer nrorep;
    @Column(name = "STRMVH_ESTREP", length = 6)
    private String estrep;
    @Column(name = "STRMVH_FCHREP")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fchrep;
    @Column(name = "STRMVH_CAMSEC", precision = 20, scale = 8)
    private BigDecimal camsec;

    @Column(name = "STRMVH_TIPOPR", length = 6)
    private String tipopr;
    @Column(name = "STRMVH_CODOPR", length = 30)
    private String codopr;

    @Column(name = "STRMVH_EMPASI", length = 10)
    private String empasi;
    @Column(name = "STRMVH_EMPREP", length = 10)
    private String emprep;
    @Column(name = "STRMVH_MODREV", length = 2)
    private String modrev;
    @Column(name = "STRMVH_CODREV", length = 6)
    private String codrev;
    @Column(name = "STRMVH_NROREV")
    private Integer nrorev;
    @Column(name = "STRMVH_EMPREV", length = 6)
    private String emprev;
    /**
     * Es comprobante de anulación
     */
    @Column(name = "STRMVH_ISANUL")
    private Character esAnulacion;


    @Column(name = "STRMVH_DOCFIS", length = 6)
    private String docfis;
    @Column(name = "STRMVH_LETFIS", length = 6)
    private String letfis;
    @Column(name = "STRMVH_SUCFIS", length = 6)
    private String sucfis;
    @Column(name = "STRMVH_NROFIS")
    private Integer nrofis;

    @Column(name = "STRMVH_CAMION", length = 6)
    private String camion;
    @Column(name = "STRMVH_NROCOT", length = 25)
    private String nrocot;
    @Column(name = "STRMVH_LOTCOT", length = 50)
    private String lotcot;

    @Embedded
    private GR_Auditoria auditoria;    

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "movimiento", fetch=FetchType.LAZY)
    private List<ST_ItemProducto> itemProducto;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "movimiento", fetch=FetchType.LAZY)
    private List<ST_ItemTransferencia> itemTransferencia;


    @Transient
    private boolean persistido;

    @Transient
    private String nserie;

    @Transient
    private String ndespa;

    @Transient
    private String envase;

    @Transient
    private String notros;


    /**
    @Column(name = "STRMVH_HORMOV", length = 10)
    private String Hormov;
    @Column(name = "STRMVH_MODULE", length = 10)
    private String Module;
    
    @Column(name = "STRMVH_LOTTRA", length = 6)
    private String Lottra;
    @Column(name = "STRMVH_LOTREC", length = 6)
    private String Lotrec;
    @Column(name = "STRMVH_LOTORI", length = 6)
    private String Lotori;
    @Column(name = "STRMVH_SYSVER", length = 10)
    private String Sysver;
    @Column(name = "STRMVH_CMPVER", length = 10)
    private String Cmpver;
    @Column(name = "STRMVH_TRACOD", length = 6)
    private String Tracod;
    */

    public ST_Movimiento() {

    }

    public ST_Movimiento(String modfor, String codfor, int nrofor, String sucurs) {
        this.modfor = modfor;
        this.codfor = codfor;
        this.nrofor = nrofor;
        this.sucurs = sucurs;
    }

    public ST_Movimiento(GR_Formulario formulario) {

        this.modfor = formulario.getModfor();
        this.codfor = formulario.getCodfor();
        this.nrofor = formulario.getUltimoNumero();
        this.sucurs = formulario.getSucursal().getSucurs();

        this.formulario = formulario;
        this.sucursal = formulario.getSucursal();

    }

    public BigDecimal getCambio() {
        return cambio;
    }

    public void setCambio(BigDecimal cambio) {
        this.cambio = cambio;
    }

    public String getCamion() {
        return camion;
    }

    public void setCamion(String camion) {
        this.camion = camion;
    }

    public BigDecimal getCamsec() {
        return camsec;
    }

    public void setCamsec(BigDecimal camsec) {
        this.camsec = camsec;
    }

    public String getCodasi() {
        return codasi;
    }

    public void setCodasi(String codasi) {
        this.codasi = codasi;
    }
   
    public String getCodfor() {
        return codfor;
    }

    public void setCodfor(String codfor) {
        this.codfor = codfor;
    }

    public String getCodopr() {
        return codopr;
    }

    public void setCodopr(String codopr) {
        this.codopr = codopr;
    }

    public String getCodrep() {
        return codrep;
    }

    public void setCodrep(String codrep) {
        this.codrep = codrep;
    }

    public String getCodrev() {
        return codrev;
    }

    public void setCodrev(String codrev) {
        this.codrev = codrev;
    }

    public String getCoflis() {
        return coflis;
    }

    public void setCoflis(String coflis) {
        this.coflis = coflis;
    }

    public String getDimobl() {
        return dimobl;
    }

    public void setDimobl(String dimobl) {
        this.dimobl = dimobl;
    }

    public String getDimori() {
        return dimori;
    }

    public void setDimori(String dimori) {
        this.dimori = dimori;
    }

    public String getDocfis() {
        return docfis;
    }

    public void setDocfis(String docfis) {
        this.docfis = docfis;
    }

    public String getEmpasi() {
        return empasi;
    }

    public void setEmpasi(String empasi) {
        this.empasi = empasi;
    }

    public String getEmprep() {
        return emprep;
    }

    public void setEmprep(String emprep) {
        this.emprep = emprep;
    }

    public String getEmprev() {
        return emprev;
    }

    public void setEmprev(String emprev) {
        this.emprev = emprev;
    }

    public String getEstrep() {
        return estrep;
    }

    public void setEstrep(String estrep) {
        this.estrep = estrep;
    }

    public Date getFchrep() {
        return fchrep;
    }

    public void setFchrep(Date fchrep) {
        this.fchrep = fchrep;
    }

    public Short getHstfor() {
        return hstfor;
    }

    public void setHstfor(Short hstfor) {
        this.hstfor = hstfor;
    }

    public Character getEsAnulacion() {
        return esAnulacion;
    }

    public void setEsAnulacion(Character esAnulacion) {
        this.esAnulacion = esAnulacion;
    }
    
    public String getLetfis() {
        return letfis;
    }

    public void setLetfis(String letfis) {
        this.letfis = letfis;
    }

    public String getLotcot() {
        return lotcot;
    }

    public void setLotcot(String lotcot) {
        this.lotcot = lotcot;
    }


    public String getModasi() {
        return modasi;
    }

    public void setModasi(String modasi) {
        this.modasi = modasi;
    }

    public GR_Formulario getFormulario() {
        return formulario;
    }

    public void setFormulario(GR_Formulario formulario) {
        this.formulario = formulario;
    }
    
    public String getModfor() {
        return modfor;
    }

    public void setModfor(String modfor) {
        this.modfor = modfor;
    }

    public String getModrep() {
        return modrep;
    }

    public void setModrep(String modrep) {
        this.modrep = modrep;
    }

    public String getModrev() {
        return modrev;
    }

    public void setModrev(String modrev) {
        this.modrev = modrev;
    }

    public Integer getNroasi() {
        return nroasi;
    }

    public void setNroasi(Integer nroasi) {
        this.nroasi = nroasi;
    }

    public String getNrocot() {
        return nrocot;
    }

    public void setNrocot(String nrocot) {
        this.nrocot = nrocot;
    }

    public Short getControlDeImpresion() {
        return controlDeImpresion;
    }

    public void setControlDeImpresion(Short controlDeImpresion) {
        this.controlDeImpresion = controlDeImpresion;
    }

    public Date getFechaMovimiento() {
        return fechaMovimiento;
    }

    public void setFechaMovimiento(Date fechaMovimiento) {
        this.fechaMovimiento = fechaMovimiento;
    }

    public String getMascara() {
        return mascara;
    }

    public void setMascara(String mascara) {
        this.mascara = mascara;
    }

    public String getNroCuentaProveedor() {
        return nroCuentaProveedor;
    }

    public void setNroCuentaProveedor(String nroCuentaProveedor) {
        this.nroCuentaProveedor = nroCuentaProveedor;
    }

    public String getNroCuentaVenta() {
        return nroCuentaVenta;
    }

    public void setNroCuentaVenta(String nroCuentaVenta) {
        this.nroCuentaVenta = nroCuentaVenta;
    }
    
    public Integer getNrofis() {
        return nrofis;
    }

    public void setNrofis(Integer nrofis) {
        this.nrofis = nrofis;
    }

    public int getNrofor() {
        return nrofor;
    }

    public void setNrofor(int nrofor) {
        this.nrofor = nrofor;
    }

    public Integer getNrorep() {
        return nrorep;
    }

    public void setNrorep(Integer nrorep) {
        this.nrorep = nrorep;
    }

    public Integer getNrorev() {
        return nrorev;
    }

    public void setNrorev(Integer nrorev) {
        this.nrorev = nrorev;
    }

    public String getSubcue() {
        return subcue;
    }

    public void setSubcue(String subcue) {
        this.subcue = subcue;
    }

    public String getSubori() {
        return subori;
    }

    public void setSubori(String subori) {
        this.subori = subori;
    }

    public String getSucfis() {
        return sucfis;
    }

    public void setSucfis(String sucfis) {
        this.sucfis = sucfis;
    }

    public String getSucurs() {
        return sucurs;
    }

    public void setSucurs(String sucurs) {
        this.sucurs = sucurs;
    }

    public String getTextos() {
        return textos;
    }

    public void setTextos(String textos) {
        this.textos = textos;
    }

    public ST_TipoMovimiento getTipoMovimiento() {
        return tipoMovimiento;
    }

    public void setTipoMovimiento(ST_TipoMovimiento tipoMovimiento) {
        this.tipoMovimiento = tipoMovimiento;
    }
    
    public String getTipopr() {
        return tipopr;
    }

    public void setTipopr(String tipopr) {
        this.tipopr = tipopr;
    }

    public ST_Deposito getDepositoEgreso() {
        return depositoEgreso;
    }

    public void setDepositoEgreso(ST_Deposito depositoEgreso) {
        this.depositoEgreso = depositoEgreso;
    }

    public ST_Deposito getDepositoIngreso() {
        return depositoIngreso;
    }

    public void setDepositoIngreso(ST_Deposito depositoIngreso) {
        this.depositoIngreso = depositoIngreso;
    }

    public ST_Sector getSectorEgreso() {
        return sectorEgreso;
    }

    public void setSectorEgreso(ST_Sector sectorEgreso) {
        this.sectorEgreso = sectorEgreso;
    }

    public ST_Sector getSectorIngreso() {
        return sectorIngreso;
    }

    public void setSectorIngreso(ST_Sector sectorIngreso) {
        this.sectorIngreso = sectorIngreso;
    }

    public boolean isPersistido() {
        return persistido;
    }

    public void setPersistido(boolean persistido) {
        this.persistido = persistido;
    }

    public GR_Comprobante getComprobante() {
        return comprobante;
    }

    public void setComprobante(GR_Comprobante comprobante) {
        this.comprobante = comprobante;
    }

    public List<ST_ItemProducto> getItemProducto() {
        return itemProducto;
    }

    public void setItemProducto(List<ST_ItemProducto> itemProducto) {
        this.itemProducto = itemProducto;
    }

    public List<ST_ItemTransferencia> getItemTransferencia() {
        return itemTransferencia;
    }

    public void setItemTransferencia(List<ST_ItemTransferencia> itemTransferencia) {
        this.itemTransferencia = itemTransferencia;
    }
    
    public GR_Sucursal getSucursal() {
        return sucursal;
    }

    public void setSucursal(GR_Sucursal sucursal) {
        this.sucursal = sucursal;
    }

    public GR_Auditoria getAuditoria() {
        return auditoria;
    }

    public void setAuditoria(GR_Auditoria auditoria) {
        this.auditoria = auditoria;
    }

    public String getEnvase() {
        return envase;
    }

    public void setEnvase(String envase) {
        this.envase = envase;
    }

    public String getNdespa() {
        return ndespa;
    }

    public void setNdespa(String ndespa) {
        this.ndespa = ndespa;
    }

    public String getNotros() {
        return notros;
    }

    public void setNotros(String notros) {
        this.notros = notros;
    }

    public String getNserie() {
        return nserie;
    }

    public void setNserie(String nserie) {
        this.nserie = nserie;
    }

    

    
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ST_Movimiento other = (ST_Movimiento) obj;
        if ((this.modfor == null) ? (other.modfor != null) : !this.modfor.equals(other.modfor)) {
            return false;
        }
        if ((this.codfor == null) ? (other.codfor != null) : !this.codfor.equals(other.codfor)) {
            return false;
        }
        if (this.nrofor != other.nrofor) {
            return false;
        }
        if ((this.sucurs == null) ? (other.sucurs != null) : !this.sucurs.equals(other.sucurs)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 67 * hash + (this.modfor != null ? this.modfor.hashCode() : 0);
        hash = 67 * hash + (this.codfor != null ? this.codfor.hashCode() : 0);
        hash = 67 * hash + this.nrofor;
        hash = 67 * hash + (this.sucurs != null ? this.sucurs.hashCode() : 0);
        return hash;
    }

    @Override
    public String toString() {
        return "ST_Movimiento{" + "modfor=" + modfor + "codfor=" + codfor + "nrofor=" + nrofor + "sucurs=" + sucurs + '}';
    }

    


}
